#include<learning.h>

char* getcwd(char*,size_t);
int chdir(const char *path);
int mkdir(const char *pathname,mode_t mode);
int rmdir(const char *pathname);

DIR *opendir(const char* name);
struct dirent *readdir(DIR *dir);
void rewinddir(DIR *dir);
void seekdir(DIR *dir,off_t offset);
off_t telldir(DIR *dir);
int closedir(DIR * dir);

int stat(const char *pathname,struct stat *buf);
int findPath(char * path,char *target)
{		
	DIR * curDir = opendir(path);
	RET_CHECK(curDir,NULL,"opendir");
	char pathbuf[1024] = {0};
	struct dirent *curNode;
	while((curNode = readdir(curDir))!=NULL)
	{
		if(strcmp(curNode->d_name,".") == 0 ||strcmp(curNode->d_name,"..") == 0)
		{
			continue;
		}	
		if(strcmp(curNode->d_name,target)==0)
		{
			printf("%s%s%s\n",path,"/",curNode->d_name);
			return 0;
		}
		if(curNode->d_type == 4)
		{
			sprintf(pathbuf,"%s%s%s",path,"/",curNode->d_name);
		
			findPath(pathbuf,target);
		}
	}
return 0;
}
int main(int argc ,char **argv){
	ARGS_CHECK(argc,3);
	findPath(argv[1],argv[2]);
	return 0;
}
